package com.example.dds.mapper;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.dds.dto.*;
import com.example.dds.model.Article;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public interface ArticleMapper{

	@Select("select * from tb_article where id=#{id}")
    Article selectByPrimaryKey(@Param("id") String id);

    @Select("show databases")
    List<String> selectByDB();


    @Select("select SUM(r.orderCount) orderCount, SUM(r.wechatOrderCount) wechatOrderCount, SUM(r.posOrderCount) posOrderCount,\n" +
            "\t\t\t SUM(r.orderPrice) orderPrice, SUM(r.peopleCount) peopleCount, SUM(r.tangshiCount) tangshiCount,\n" +
            "\t\t\t SUM(r.tangshiPrice) tangshiPrice,SUM(r.waidaiCount) waidaiCount, SUM(r.waidaiPrice) waidaiPrice,\n" +
            "\t\t\t SUM(r.waimaiCount) waimaiCount, SUM(r.waimaiPrice) waimaiPrice, SUM(r.orderPosDiscountMoney) orderPosDiscountMoney\n" +
            "\t\t\t , SUM(r.memberDiscountMoney) memberDiscountMoney, SUM(r.realEraseMoney) realEraseMoney\n" +
            "\t\tfrom (\n" +
            "\t\tSELECT\n" +
            "\t\t\tIF(ISNULL(parent_order_id), 1, 0)  orderCount,\n" +
            "\t\t\tIF(ISNULL(parent_order_id) AND o.data_origin = 1 AND o.customer_id != '0', 1, 0) wechatOrderCount,\n" +
            "\t\t\tIF(ISNULL(parent_order_id) AND (o.data_origin = 0 OR (o.data_origin = 1 and o.customer_id = '0')), 1, 0) posOrderCount,\n" +
            "\t\t\tIF(ISNULL(parent_order_id), O.customer_count, 0) peopleCount,\n" +
            "\t\t\tIF(o.distribution_mode_id = 1 AND ISNULL(o.parent_order_id), 1, 0) tangshiCount,\n" +
            "\t\t\tIF(o.distribution_mode_id = 3 AND ISNULL(o.parent_order_id), 1, 0) waidaiCount,\n" +
            "\t\t\tIF(o.distribution_mode_id = 2 AND ISNULL(o.parent_order_id), 1, 0) waimaiCount,\n" +
            "\t\t\to.order_money + IFNULL((o.order_pos_discount_money + o.reduce_money) + o.member_discount_money + o.real_erase_money , 0) orderPrice,\n" +
            "\t\t\tIF(o.distribution_mode_id=1, o.order_money + IFNULL((o.order_pos_discount_money + o.reduce_money) + o.member_discount_money + o.real_erase_money, 0) , 0) tangshiPrice,\n" +
            "\t\t\tIF(o.distribution_mode_id=3, o.order_money + IFNULL((o.order_pos_discount_money + o.reduce_money) + o.member_discount_money + o.real_erase_money, 0) , 0) waidaiPrice,\n" +
            "\t\t\tIF(o.distribution_mode_id=2, o.order_money + IFNULL((o.order_pos_discount_money + o.reduce_money) + o.member_discount_money + o.real_erase_money, 0) , 0) waimaiPrice,\n" +
            "\t\t\t(o.order_pos_discount_money + o.reduce_money) orderPosDiscountMoney,\n" +
            "\t\t\to.member_discount_money memberDiscountMoney,\n" +
            "\t\t\to.real_erase_money realEraseMoney\n" +
            "\t\tFROM tb_order o\n" +
            "\t\tLEFT JOIN tb_order_item toi\n" +
            "\t\ton o.id = toi.order_id\n" +
            "\t\tGROUP BY o.id\n" +
            "        ) r")
    List<String> selectOrder();

    @Select("select * from tb_order")
    List<String> selectByOrderList();

    @Select("select * from tb_order_item")
    List<String> selectByOrderItemList();

    @Select("call test_call")//存储过程
    List<String> selectCall();

    @Select("SELECT shop_id shopId,shop_name shopName FROM tb_longjue WHERE shop_id IS NOT NULL")//店铺
    List<Shop> selectShops();

    @Select("SELECT date FROM tb_longjue_date ORDER BY date ASC")//日期
    List<String> selectDate();

    @Select("CALL TianCaiOrder(#{date},#{shopId})")//天财订单数据
//    @Select("CALL TianCaiOrderTakeaway(#{date},#{shopId})")//外卖
    List<Order> selectTianCaiOrders(String date,String shopId);

    @Select("CALL TianCaiOrderItem(#{date},#{shopId})")//天财订单详情数据
//    @Select("CALL TianCaiOrderItemTakeaway(#{date},#{shopId})")//外卖
    List<OrderItem> TianCaiOrderItem(String date, String shopId);

    @Select("CALL TianCaiOrderPaymentItem(#{date},#{shopId})")//天财支付详情数据
//    @Select("CALL TianCaiOrderPaymentItemTakeaway(#{date},#{shopId})")//外卖
    List<OrderPaymentItem> TianCaiOrderPaymentItem(String date, String shopId);


    @Select("CALL TianCaiKitchen(#{date},#{shopId})")//天财厨打数据
//    @Select("CALL TianCaiKitchenTakeaway(#{date},#{shopId})")//外卖
    List<Kitchen> TianCaiKitchen(String date, String shopId);

    @Select("CALL TianCaiMemberConsum(#{date},#{shopId})")//天财会员消费数据
    List<MemberConsum> TianCaiMemberConsum(String date, String shopId);

    @Select("CALL TianCaiMemberStored(#{date},#{shopId})")//天财会员储值数据
    List<MemberStored> TianCaiMemberStored(String date, String shopId);
}